package com.ct.gd.passport.view.travel;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.MapActivity;
import com.baidu.mapapi.MapController;
import com.baidu.mapapi.MapView;
import com.ct.gd.passport.R;
import com.ct.gd.passport.common.constants.Config;

public class MapTrafficActivity extends MapActivity {

	BMapManager	mBMapMan	= null;
	
    protected ImageButton		mBtnLeft;      // 头部左边图标按钮
    
    protected ImageButton		mBtnRight;      // 头部右边图标按钮
    
    protected TextView      mHeaderTitleTv;    // 头部标题文字

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.traffic);
		
    	mBtnLeft = (ImageButton) findViewById(R.id.btn_header_left);
    	mBtnRight = (ImageButton) findViewById(R.id.btn_header_right);
    	mHeaderTitleTv = (TextView) findViewById(R.id.tv_header_center);
    	mHeaderTitleTv.setText(R.string.travelAssist_traffic);
    	
    	mBtnLeft.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				MapTrafficActivity.this.finish();
			}
		});
		
		mBMapMan = new BMapManager(getApplication());
		mBMapMan.init(Config.BAIDU_MAP_KEY, null);
		super.initMapActivity(mBMapMan);
		 
		MapView mMapView = (MapView) findViewById(R.id.bmapsView);
		mMapView.setBuiltInZoomControls(true);  //设置启用内置的缩放控件
		 
		MapController mMapController = mMapView.getController();  // 得到mMapView的控制权,可以用它控制和驱动平移和缩放
//		GeoPoint point = new GeoPoint((int) (Config.getPosition()[0] * 1E6),
//		        (int) (Config.getPosition()[1]  * 1E6)); 
		GeoPoint point = new GeoPoint((int) (Config.currentArea.jw[0] * 1E6),
				 (int)(Config.currentArea.jw[1]  * 1E6)); //用给定的经纬度构造一个GeoPoint，单位是微度 (度 * 1E6)
		mMapController.setCenter(point);  //设置地图中心点
		mMapController.setZoom(12);    //设置地图zoom级别
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

	@Override
	protected void onDestroy() {
	    if (mBMapMan != null) {
	        mBMapMan.destroy();
	        mBMapMan = null;
	    }
	    super.onDestroy();
	}
	@Override
	protected void onPause() {
	    if (mBMapMan != null) {
	        mBMapMan.stop();
	    }
	    super.onPause();
	}
	@Override
	protected void onResume() {
	    if (mBMapMan != null) {
	        mBMapMan.start();
	    }
	    super.onResume();
	}
}